home *** CD-ROM | disk | FTP | other *** search
/ Cre@te Online 2000 December / Cre@teOnline CD05.iso / MacSoft / XML Authority.sea / XML Authority / Required / RC.jar / com / extensibility / app / BaseApplication.class (.txt) < prev    next >
Encoding:
Java Class File  |  2000-07-05  |  13.5 KB  |  586 lines

  1. package com.extensibility.app;
  2.  
  3. import com.extensibility.app.plugin.URIResourcePlugin;
  4. import com.extensibility.plugin.PluginRegistry;
  5. import com.extensibility.rock.AltGrPatch;
  6. import com.extensibility.rock.Platform;
  7. import com.extensibility.rock.RDialog;
  8. import com.extensibility.util.Debug;
  9. import com.extensibility.util.Security;
  10. import com.extensibility.xml.URI;
  11. import java.awt.Component;
  12. import java.awt.Font;
  13. import java.awt.Frame;
  14. import java.awt.Window;
  15. import java.awt.event.ActionEvent;
  16. import java.io.File;
  17. import java.io.FileOutputStream;
  18. import java.io.IOException;
  19. import java.io.PrintStream;
  20. import java.io.Writer;
  21. import java.net.URL;
  22. import java.util.Date;
  23. import java.util.Enumeration;
  24. import java.util.EventObject;
  25. import java.util.Vector;
  26. import javax.swing.JFrame;
  27. import javax.swing.JOptionPane;
  28. import javax.swing.UIManager;
  29.  
  30. public abstract class BaseApplication implements Platform.Application {
  31.    static final String PRINT_TEMPLATE = "_print_template";
  32.    static final byte REG_VERSION = 1;
  33.    protected static BaseApplication oneAndOnly;
  34.    // $FF: renamed from: ui com.extensibility.app.UI
  35.    static UI field_0;
  36.    private final Registration newreg = new Registration(this);
  37.    protected Security registration;
  38.    private ApplicationPreferences prefs;
  39.    protected Vector listeners = new Vector();
  40.    static File homePath;
  41.    BaseAction showHideToolbarAction;
  42.    // $FF: synthetic field
  43.    static Class class$com$extensibility$app$BaseApplication;
  44.  
  45.    public BaseApplication() {
  46.       new AltGrPatch();
  47.       oneAndOnly = this;
  48.    }
  49.  
  50.    public static BaseApplication getApplication() {
  51.       return oneAndOnly;
  52.    }
  53.  
  54.    public static String getPreference(String var0) {
  55.       return getApplication().prefs.getProperty(var0);
  56.    }
  57.  
  58.    public static ApplicationPreferences getPreferences() {
  59.       return getApplication().prefs;
  60.    }
  61.  
  62.    public static String getPreference(String var0, int var1) {
  63.       return getApplication().prefs.getProperty(var0 + var1);
  64.    }
  65.  
  66.    public static UI getUI() {
  67.       return field_0;
  68.    }
  69.  
  70.    public static boolean isDebug() {
  71.       if (getPreferences() != null) {
  72.          return getPreferences().getDebugLevel() > 0;
  73.       } else {
  74.          return true;
  75.       }
  76.    }
  77.  
  78.    public static int getDebugLevel() {
  79.       return getPreferences() != null ? getPreferences().getDebugLevel() : 2;
  80.    }
  81.  
  82.    public static File getHomePath() {
  83.       if (homePath != null) {
  84.          return homePath;
  85.       } else {
  86.          String var0 = System.getProperty("java.class.path");
  87.  
  88.          while(var0 != null) {
  89.             int var2 = var0.indexOf(System.getProperty("path.separator"));
  90.             String var1;
  91.             if (var2 >= 0) {
  92.                var1 = var0.substring(0, var2);
  93.                var0 = var0.substring(var2 + 1);
  94.             } else {
  95.                var1 = var0;
  96.                var0 = null;
  97.             }
  98.  
  99.             if (var1.length() != 0) {
  100.                File var3 = new File(var1);
  101.                if (var3.isDirectory()) {
  102.                   if ((new File(var1, (class$com$extensibility$app$BaseApplication != null ? class$com$extensibility$app$BaseApplication : (class$com$extensibility$app$BaseApplication = class$("com.extensibility.app.BaseApplication"))).getName().replace('.', File.separatorChar) + ".class")).exists()) {
  103.                      homePath = new File(var3.getParent());
  104.                      break;
  105.                   }
  106.                } else if (var3.getName().equalsIgnoreCase(getApplication().getAbbr() + ".jar")) {
  107.                   String var4 = var3.getParent();
  108.                   if (var4 == null) {
  109.                      var4 = System.getProperty("user.dir");
  110.                   }
  111.  
  112.                   homePath = new File(var4);
  113.                   break;
  114.                }
  115.             }
  116.          }
  117.  
  118.          Debug.assert(homePath != null, "Unable to locate home path within " + System.getProperty("java.class.path") + ". Looked for: " + getApplication().getAbbr() + ".jar");
  119.          return homePath;
  120.       }
  121.    }
  122.  
  123.    public void reregister() {
  124.       this.newreg.reregister();
  125.    }
  126.  
  127.    public static Date getExpiration() {
  128.       return Registration.getExpirationDate();
  129.    }
  130.  
  131.    private void register() {
  132.       this.newreg.register();
  133.    }
  134.  
  135.    public void openDocumentList(String[] var1) {
  136.       for(int var2 = 0; var2 < var1.length; ++var2) {
  137.          if (!var1[var2].equals("-quiet")) {
  138.             if (var1[var2].charAt(0) == '"' && var1[var2].charAt(var1[var2].length() - 1) == '"') {
  139.                var1[var2] = var1[var2].substring(1, var1[var2].length() - 1);
  140.             }
  141.  
  142.             this.openDocument(new File(var1[var2]));
  143.          }
  144.       }
  145.  
  146.    }
  147.  
  148.    public void doArgs(String[] var1) {
  149.       if (var1 != null && var1.length > 0 && var1[0].length() > 0) {
  150.          Desktop.createSplash();
  151.          Desktop.createWelcome(false);
  152.          this.openDocumentList(var1);
  153.       } else if (getPreferences().getShowWelcome()) {
  154.          Desktop.createWelcome(true);
  155.          this.preflight();
  156.       } else {
  157.          Desktop.createSplash();
  158.          Desktop.createWelcome(false);
  159.          this.newDocument((EventObject)null);
  160.       }
  161.  
  162.       this.fireApplicationStarted();
  163.    }
  164.  
  165.    protected String[] getSaveTypes() {
  166.       return this.getOpenTypes();
  167.    }
  168.  
  169.    protected abstract String[] getOpenTypes();
  170.  
  171.    public abstract BaseDocument createNewDocument(EventObject var1);
  172.  
  173.    public abstract BaseDocument createNewDocument(URI var1);
  174.  
  175.    protected abstract UI createUI();
  176.  
  177.    protected abstract Class getMainWindowClass();
  178.  
  179.    protected abstract BaseWindow createNewWindow(BaseDocument var1);
  180.  
  181.    protected abstract ApplicationPreferences createPreferences();
  182.  
  183.    protected abstract String getAbbr();
  184.  
  185.    public abstract String getVersion();
  186.  
  187.    public abstract RDialog createPreferencesDialog(JFrame var1);
  188.  
  189.    public abstract JFrame createWelcome();
  190.  
  191.    public abstract RDialog createPrintDialog(Frame var1);
  192.  
  193.    public void startup() throws Exception {
  194.       field_0 = this.createUI();
  195.       field_0.initResources();
  196.       Platform.initialize(this);
  197.       this.prefs = this.createPreferences();
  198.       this.prefs.readInitial(new File(getHomePath(), this.getAbbr() + "_Preferences"));
  199.       Font var1 = this.prefs.getAppFont();
  200.       if (var1 != null) {
  201.          field_0.setAppFont(var1);
  202.       }
  203.  
  204.       var1 = this.prefs.getDocFont();
  205.       if (var1 != null) {
  206.          field_0.setDocFont(var1);
  207.       }
  208.  
  209.       var1 = this.prefs.getSrcFont();
  210.       if (var1 != null) {
  211.          field_0.setSrcFont(var1);
  212.       }
  213.  
  214.       try {
  215.          String var2 = this.prefs.getLookAndFeel();
  216.          UIManager.setLookAndFeel(var2);
  217.       } catch (Exception var3) {
  218.       }
  219.  
  220.       Debug.setCatcher(this.createCatcher());
  221.       this.register();
  222.       this.registration = this.newreg.getRegistration();
  223.       if (getDebugLevel() > 1) {
  224.          System.setOut(new PrintStream(new FileOutputStream(new File("console-out.txt"))));
  225.          System.setErr(new PrintStream(new FileOutputStream(new File("console-err.txt"))));
  226.       }
  227.  
  228.       if (this.newreg.isLaunchLimited()) {
  229.          this.prefs.updateLaunchesLeft(this.prefs.getLaunchesLeft() - 1);
  230.       }
  231.  
  232.       this.doPluginRegistration();
  233.    }
  234.  
  235.    protected void doPluginRegistration() {
  236.       String var1 = UI.getString("plugin.folder");
  237.       if (var1.startsWith("#MISSING")) {
  238.          var1 = "plugins";
  239.       }
  240.  
  241.       File var2 = new File(getHomePath(), var1);
  242.       PluginRegistry var3 = new PluginRegistry();
  243.       PluginRegistry.setRegistry(var3);
  244.       var3.registerPluginsInFolder(var2);
  245.       URIResourcePlugin.registerPlugin(var3);
  246.    }
  247.  
  248.    protected Debug.Catcher createCatcher() {
  249.       return new 1();
  250.    }
  251.  
  252.    public void quit() {
  253.       this.exitApplication((EventObject)null);
  254.    }
  255.  
  256.    public void openAboutWindow() {
  257.       Desktop.createAboutWindow();
  258.    }
  259.  
  260.    public void printDocument(File var1) {
  261.    }
  262.  
  263.    public void exitApplication(EventObject var1) {
  264.       Vector var2 = Desktop.getWindows();
  265.  
  266.       for(int var3 = var2.size() - 1; var3 >= 0; --var3) {
  267.          BaseWindow var4 = (BaseWindow)var2.elementAt(var3);
  268.          if (!var4.getDocument().isOkToClose(var4)) {
  269.             return;
  270.          }
  271.       }
  272.  
  273.       for(int var8 = var2.size() - 1; var8 >= 0; --var8) {
  274.          BaseWindow var5 = (BaseWindow)var2.elementAt(var8);
  275.          ((Frame)var5).dispose();
  276.       }
  277.  
  278.       try {
  279.          this.prefs.save();
  280.       } catch (IOException var6) {
  281.          DialogFactory.showException((Component)null, 108, var6);
  282.       } catch (Throwable var7) {
  283.          Debug.assert(false, "Got a non io error exiting application: " + var7);
  284.       }
  285.  
  286.       this.fireApplicationExited();
  287.       System.exit(0);
  288.    }
  289.  
  290.    private void preflight() {
  291.    }
  292.  
  293.    public static byte getRegVersion() {
  294.       return 1;
  295.    }
  296.  
  297.    public static boolean isLaunchLimited() {
  298.       return getApplication().newreg.isLaunchLimited();
  299.    }
  300.  
  301.    public static int getLaunchesLeft() {
  302.       return getApplication().prefs.getLaunchesLeft();
  303.    }
  304.  
  305.    public boolean openDocumentURL(ActionEvent var1) {
  306.       String[] var2 = this.getOpenTypes();
  307.       String var3 = getPreferences().getOpenFromBase();
  308.       URI var4 = null;
  309.       if (var3 != null) {
  310.          var4 = new URI((URI)null, var3);
  311.       }
  312.  
  313.       URI var5 = DialogFactory.openURI(Desktop.getDialogParent(var1), var4, var2);
  314.       if (var5 == null) {
  315.          return false;
  316.       } else {
  317.          this.openDocument(var5);
  318.          return true;
  319.       }
  320.    }
  321.  
  322.    public boolean saveDocumentTo(ActionEvent var1, BaseDocument var2) {
  323.       Object var3 = null;
  324.       String var4 = getPreferences().getSaveToBase();
  325.       URI var5 = var2.getURI();
  326.       if (var5.isURL()) {
  327.          var4 = var5.getFullName();
  328.       } else {
  329.          String var6 = var2.getName();
  330.          if (var4 == null) {
  331.             var4 = var6;
  332.          } else {
  333.             if (!var4.endsWith("/")) {
  334.                var4 = var4 + "/";
  335.             }
  336.  
  337.             var4 = var4 + var6;
  338.          }
  339.       }
  340.  
  341.       URI var11 = new URI((URI)null, var4);
  342.       URI var7 = DialogFactory.saveURI(Desktop.getDialogParent(var1), var11, (String[])var3);
  343.       if (var7 == null) {
  344.          return false;
  345.       } else if (!var7.isURL()) {
  346.          DialogFactory.stop((Component)null, "You must provide a valid URL.");
  347.          return false;
  348.       } else if (var7.exists() && !DialogFactory.showConfirm((Component)null, UI.getString("stop.uri.exists", var7.getFullName()), UI.getString("dialog.replace.title"))) {
  349.          return false;
  350.       } else {
  351.          try {
  352.             Writer var8 = var7.createWriter();
  353.             var2.write(var8);
  354.             var8.close();
  355.             return true;
  356.          } catch (Exception var9) {
  357.             DialogFactory.showException((Component)null, 103, var9, var7.getShortName());
  358.             return false;
  359.          }
  360.       }
  361.    }
  362.  
  363.    public BaseDocument newDocument(EventObject var1) {
  364.       BaseDocument var2 = this.createNewDocument(var1);
  365.  
  366.       try {
  367.          BaseWindow var3 = this.getMainWindow(var2);
  368.          ((Component)var3).setVisible(true);
  369.       } catch (Exception var5) {
  370.          String var4 = Platform.mapNewlinesForTextArea(Debug.getStackTrace(var5));
  371.          JOptionPane.showMessageDialog(new JFrame(), var4);
  372.          Desktop.ensureWindow();
  373.       }
  374.  
  375.       return var2;
  376.    }
  377.  
  378.    public boolean openDocument(URI var1) {
  379.       BaseDocument var2 = Desktop.getDocument(var1);
  380.       if (var2 != null) {
  381.          DialogFactory.stop((Component)null, UI.getString("stop.already.open", var1.getShortName()));
  382.          Desktop.activateDocument(var2);
  383.          return true;
  384.       } else {
  385.          BaseDocument var3 = this.createNewDocument(var1);
  386.  
  387.          try {
  388.             var3.read(var1);
  389.             this.updateFileLists(var1);
  390.             this.getMainWindow(var3);
  391.             this.fireDocumentOpened(var1);
  392.             return true;
  393.          } catch (Exception var5) {
  394.             DialogFactory.showException((Component)null, 102, var5);
  395.             return false;
  396.          }
  397.       }
  398.    }
  399.  
  400.    public BaseWindow getMainWindow(BaseDocument var1) {
  401.       BaseWindow var2 = var1.getWindow(this.getMainWindowClass());
  402.       if (var2 != null) {
  403.          ((Window)var2).toFront();
  404.          return var2;
  405.       } else {
  406.          var2 = this.createNewWindow(var1);
  407.          Desktop.positionNewWindow(var2);
  408.          var2.initialize(getPreferences());
  409.          Desktop.showNewWindow(var2, true);
  410.          return var2;
  411.       }
  412.    }
  413.  
  414.    public void createAnotherWindow(BaseDocument var1) {
  415.       BaseWindow var2 = this.createNewWindow(var1);
  416.       Desktop.positionNewWindow(var2);
  417.       var2.initialize((ApplicationPreferences)null);
  418.       Desktop.showNewWindow(var2, false);
  419.    }
  420.  
  421.    public boolean openDocument(ActionEvent var1) {
  422.       File var2 = DialogFactory.askFile(Desktop.getDialogParent(var1), UI.getString("dialog.open.schema"), this.getOpenTypes());
  423.       return var2 == null ? false : this.openDocument(new URI(var2));
  424.    }
  425.  
  426.    public void saveNotify(URI var1, BaseDocument var2) {
  427.       Enumeration var3 = Desktop.getDocuments();
  428.  
  429.       while(var3.hasMoreElements()) {
  430.          BaseDocument var4 = (BaseDocument)var3.nextElement();
  431.          if (var4 != var2) {
  432.             var4.saveNotify(var1);
  433.          }
  434.       }
  435.  
  436.       this.fireDocumentSaved(var1);
  437.    }
  438.  
  439.    public void updateFileLists(URI var1) {
  440.       this.prefs.updateRecent(var1);
  441.       this.updateRecentMenu();
  442.       this.updateWindowMenu();
  443.    }
  444.  
  445.    public void removeFromRecent(URI var1) {
  446.       this.prefs.removeFromRecent(var1);
  447.       this.updateRecentMenu();
  448.    }
  449.  
  450.    private void updateWindowMenu() {
  451.       Enumeration var1 = Desktop.getWindows().elements();
  452.  
  453.       while(var1.hasMoreElements()) {
  454.          BaseWindow var2 = (BaseWindow)var1.nextElement();
  455.          var2.fillWindowsMenu();
  456.       }
  457.  
  458.    }
  459.  
  460.    private void updateRecentMenu() {
  461.       Enumeration var1 = Desktop.getWindows().elements();
  462.  
  463.       while(var1.hasMoreElements()) {
  464.          BaseWindow var2 = (BaseWindow)var1.nextElement();
  465.          var2.updateRecentMenuItems();
  466.       }
  467.  
  468.    }
  469.  
  470.    public void updateNewSubMenu() {
  471.       Enumeration var1 = Desktop.getWindows().elements();
  472.  
  473.       while(var1.hasMoreElements()) {
  474.          BaseWindow var2 = (BaseWindow)var1.nextElement();
  475.          String var3 = getPreferences().getDefaultFileType();
  476.          var2.updateNewSubMenuItems(UI.getFileTypeName(var3));
  477.       }
  478.  
  479.    }
  480.  
  481.    public BaseAction createToolbarAction() {
  482.       if (this.showHideToolbarAction == null) {
  483.          this.showHideToolbarAction = new 2(this, "item.tb");
  484.          this.showHideToolbarAction.setSelected(this.prefs.getToolbarView() == 1);
  485.       }
  486.  
  487.       return this.showHideToolbarAction;
  488.    }
  489.  
  490.    private void updateToolBarView(int var1) {
  491.       this.prefs.updateToolBarView(var1);
  492.       Enumeration var2 = Desktop.getWindows().elements();
  493.  
  494.       while(var2.hasMoreElements()) {
  495.          BaseWindow var3 = (BaseWindow)var2.nextElement();
  496.          var3.updateToolBarView();
  497.       }
  498.  
  499.    }
  500.  
  501.    public boolean openDocument(URL var1) {
  502.       return this.openDocument(new URI(var1));
  503.    }
  504.  
  505.    public boolean openDocument(File var1) {
  506.       return this.openDocument(new URI(var1));
  507.    }
  508.  
  509.    public void addApplicationListener(ApplicationListener var1) {
  510.       this.listeners.addElement(var1);
  511.    }
  512.  
  513.    public void removeApplicationListener(ApplicationListener var1) {
  514.       this.listeners.removeElement(var1);
  515.    }
  516.  
  517.    public void fireApplicationStarted() {
  518.       Enumeration var1 = this.listeners.elements();
  519.  
  520.       while(var1.hasMoreElements()) {
  521.          ApplicationListener var2 = (ApplicationListener)var1.nextElement();
  522.          var2.applicationStarted();
  523.       }
  524.  
  525.    }
  526.  
  527.    public void fireApplicationExited() {
  528.       Enumeration var1 = this.listeners.elements();
  529.  
  530.       while(var1.hasMoreElements()) {
  531.          ApplicationListener var2 = (ApplicationListener)var1.nextElement();
  532.          var2.applicationExited();
  533.       }
  534.  
  535.    }
  536.  
  537.    public void fireDocumentOpened(URI var1) {
  538.       Enumeration var2 = this.listeners.elements();
  539.  
  540.       while(var2.hasMoreElements()) {
  541.          ApplicationListener var3 = (ApplicationListener)var2.nextElement();
  542.          var3.documentOpened(var1);
  543.       }
  544.  
  545.    }
  546.  
  547.    public void fireDocumentSaved(URI var1) {
  548.       Enumeration var2 = this.listeners.elements();
  549.  
  550.       while(var2.hasMoreElements()) {
  551.          ApplicationListener var3 = (ApplicationListener)var2.nextElement();
  552.          var3.documentSaved(var1);
  553.       }
  554.  
  555.    }
  556.  
  557.    public void fireDocumentClosed(URI var1) {
  558.       Enumeration var2 = this.listeners.elements();
  559.  
  560.       while(var2.hasMoreElements()) {
  561.          ApplicationListener var3 = (ApplicationListener)var2.nextElement();
  562.          var3.documentClosed(var1);
  563.       }
  564.  
  565.    }
  566.  
  567.    // $FF: synthetic method
  568.    static Class class$(String var0) {
  569.       try {
  570.          return Class.forName(var0);
  571.       } catch (ClassNotFoundException var2) {
  572.          throw new NoClassDefFoundError(((Throwable)var2).getMessage());
  573.       }
  574.    }
  575.  
  576.    // $FF: synthetic method
  577.    static ApplicationPreferences access$0(BaseApplication var0) {
  578.       return var0.prefs;
  579.    }
  580.  
  581.    // $FF: synthetic method
  582.    static void access$1(BaseApplication var0, int var1) {
  583.       var0.updateToolBarView(var1);
  584.    }
  585. }
  586.